<?php

namespace JsonLowCode\Form;

use Closure;
use JsonLowCode\UI\TabPane;
use JsonLowCode\UI\Tabs as TabsUI;
use JsonLowCode\Form\Abstract\FormAbstract;

/**
 * @property TabsUI $element
 * @method TabsUI element()
 */
class Tabs extends FormAbstract
{
    protected function booted(): void
    {
        $this->element = new TabsUI();
        $this->element->class("shadow-sm");
        $this->element->styles([
            'border'=>"1px solid var(--n-color-segment)",
            "padding"=>"0 8px",
            "margin"=>"15px 0"
        ]);
    }

    /**
     * 设置标签页
     * @param string $tab 标签名称
     * @param Closure $children 子元素回调
     * @param Closure|null $closure tabPane 组件回调
     * @return $this
     */
    public function tab(string $tab, Closure $children, Closure $closure = null): static
    {
        $count = $this->element->getOptionCount();
        $tabPane = new TabPane($count, $tab);
        if ($closure instanceof Closure){
            call_user_func($closure,$tabPane);
        }
        $this->element->addOptions($tabPane->getProps());
        $formBuilder = new Make($this->build);
        call_user_func($children, $formBuilder);
        $this->element->addSlotOptions($tab, $formBuilder);
        return $this;
    }
}
